home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character - Making a better fgets?
- Date: 19 Apr 1996 09:06:54 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4l8dmuINN6lf@keats.ugrad.cs.ubc.ca>
- References: <31616F63.481D@lava.weeg.uiowa.edu> <DpBuF6.83C@ukpsshp1.serigate.philips.nl> <3169994D.665ACF69@cs.ucl.ac.uk> <4l6flq$rck@mark.ucdavis.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4l6flq$rck@mark.ucdavis.edu>,
- James Knight <knight@quad.cs.ucdavis.edu> wrote:
- > 4.5MB, 1MB,
- > short lines one line
- > ----------- --------
- >1) fgetc/fputc 23.00 5.32
- >2) getc/putc 17.56 4.09
- >3) fgets/fputs 17.80 N/A
- >4) my_getline 17.52 3.96
- >5) freadln 19.70 4.20
- >6) reimplement 19.82 4.44
- >7) optimize 18.22 4.22
- >8) read/write 9.65 1.46
-
- >Now, this actually suprised the heck out of me, so I reran the test
- >for 2, 3, 4 and 5 a number of times. Even though I wrote my_getline,
- >I never expected it to be as fast as the getc/putc version. Could
-
- Told you so. :) I'm not a _total_ idiot, you know...
-
- By the way, W. Stevens in _Advanced Programming in the UNIX Environment_
- compares a copy program implemented using read()/write() versus one that uses
- memory mapped files. The mapped copy is significantly faster still. Perhaps a
- line reversal algorithm using memory mapped files would beat #8.
-
- The reversal forces you to buffer a whole line, which one would expect would
- level the performance difference between the line reading functions and a
- getc() loop. But it didn't happen in your case.
-
- Now suppose that you were to write a program that could be implemented in such
- a way that it would _not_ have to retain a whole line at a time. The
- performance gap would probably be wider still, on your particular system.
-
- Also what is interesting that the fgetc()/fputc() version is the _slowest_,
- which indicates that function calls are still expensive no matter what anyone
- says. In particular, on a UNIX system, the standard library functions force you
- to jump to a shared library, which is often slower than jumping to a statically
- linked one, particularly if jump tables are used. Perhaps including in your
- test a statically linked version of some of the programs might be revealing of
- something as well.
-